<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
if (!ispost())
{
    exit();
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval(getvar("gametype"));
$chk = new CheckMode_3d($curruser['acl'], 3, $gametype);
$chk->checkShow3dPage();
$betname_sb = judge_type($gametype);
unset($chk);

$tbl = $g_gametype_3d[$gametype]['en'];
$tblName = $g_gametype_3d[$gametype]['ch'];
if (20 < $gametype)
{
    $_8hFlag = true;
}
else
{
    $_8hFlag = false;
}
require_once( "class_sb/RateConfig_sb.php" );
require_once( "class_sb/SRate_sb.php" );
$ui = new UI_3D(true);
$conf = new Config();
$RateConfig_sb = new RateConfig_sb($gametype);
$SRate_sb = new SRate_sb($gametype);
$today = date("Y-m-d");
$bettypegroup = getvar("palygroup");
unset($_POST['bettypegroup']);
$pounNum = $RateConfig_sb->pounNum;
$rcbettype = 0;
$betmin = intval($conf->get("betmin_{$tbl}"));
$betmin2face = intval($conf->get("betmin2face_{$tbl}"));
if ($betmin2face <= 0)
{
    $betmin2face = $betmin;
}
if ($curruser['enabled'] == 0 || $curruser['enabled'] == 2)
{
    $ui->showErrorPage("帐号已被暂停使用");
    exit();
}
else if (1 < $curruser['acl'])
{
    $ui->showErrorPage("非会员无法下注");
    exit();
}
$disk = intval(getvar("disk"));
if (!isset($curruser["disk{$disk}"]) || $curruser["disk{$disk}"] != 1)
{
    $ui->showErrorPage("盘类错误");
    exit();
}
unset($_POST['disk']);
$diskStr = $RateConfig_sb->diskArr[$disk];
$diskStr2 = $g_disk_name[$disk];
if ($bettypegroup == "" || !isset($RateConfig_sb->playGroupArr[$bettypegroup]))
{
    $ui->showErrorPage("{$tblName}-不正确的玩法页面");
    exit();
}
$subid = 0 - 1;
$bettype = 0 - 1;
$nums = "";
include_once( "BetChk.php" );
$BetChk = new BetChk($today, $gametype);
if ($lotto = $BetChk->chkBetDate($today))
{
    $lotto_id = $lotto['id'];
    $round = $lotto['round'];
    $showBetTable = array ();
    $rateArr = array ();
    $amountsDataArr = array ();
    $user_id = $SRate_sb->getAcl5ID($curruser['id'], $curruser['acl']);

    foreach ($_POST as $key => $val)
    {
        $betOKFlag = true;
        $tempArr = array ();
        $val = intval($val);
        if (empty($val) || $val < 1)
        {
            $betOKFlag = false;
            continue;
        }
        $dataArrTemp = explode("_", $key);
        if (count($dataArrTemp) != 2)
        {
            $betOKFlag = false;
            continue;
        }
        $subid = 0;
        $bettype = intval(str_replace('r','',$dataArrTemp[0]));
        $nums = "";
        $err = 0;

        if (array_key_exists($bettype, $_sb_Arr))
        {
            $bettype = intval($bettype);
        }
        else
        {
			$bettype-1;
            $err = 1;
        }

        $betnameIdx = $bettype;
        if (!isset($betname_sb[$betnameIdx]))
        {
            $betOKFlag = false;
            $timeTemp = rand(0, 9999);
            $errMsg = "({$tbl})[betbeforedo]No.{$timeTemp}-9 会员下注:不正确的玩法类别:xyid-{$xyidGet}, subid-{$subid}, bettype-{$bettype}";
            write_exceptional_log($curruser['id'], $curruser['acl'], $lotto_id, $errMsg);
            $ui->showErrorPage("下注失败，若有任何问题请洽管理员(errorNo.{$timeTemp})");
            ++$err;
            exit();
        }

        $nums = d2(intval($dataArrTemp[1]));
		
        if ($err)
        {
            $betOKFlag = false;
            $timeTemp = rand(0, 9999);
            $errMsg = "({$tbl})[betbeforedo]No.{$timeTemp}-1 会员下注:不正确的格式:xyid-{$xyid}, subid-{$subid}, bettype-{$bettype}, nums-{$nums}";
            write_exceptional_log($curruser['id'], $curruser['acl'], $lotto_id, $errMsg);
            $ui->showErrorPage("下注失败，若有任何问题请洽管理员(errorNo.{$timeTemp})");
            exit();
        }
        else if (!$RateConfig_sb->checkBetNumber($bettype, $nums))
        {
            $betOKFlag = false;
            $timeTemp = rand(0, 9999);
            $errMsg = "({$tbl})[betbeforedo]No.{$timeTemp}-2 会员下注:不正确的内容:id-" . $bettype . ",num-" . $nums;
            write_exceptional_log($curruser['id'], $curruser['acl'], $lotto_id, $errMsg);
            $ui->showErrorPage("下注失败，若有任何问题请洽管理员(errorNo.{$timeTemp})");
            exit();
        }
        $betmin_tmp = in_array($bettype, $g_2face_sb) ? $betmin2face : $betmin;
        $betnameIdx = $bettype;
        if ($val < $betmin_tmp)
        {
            $betOKFlag = false;
            $showBetTable[] = array ("subid" => $subid, "bettype" => $betname_sb[$betnameIdx], "nums" => $RateConfig_sb->getBetContent($bettype, $nums), "rate" => "--", "betmoney" => "<font class=\"red\">下注金额不能小於最低限额({$betmin_tmp}元)</font>", "betflag" => false);
            continue;
        }
        if (!isset($rateArr[$betnameIdx]))
        {
            $tempRateBaseArr = $SRate_sb->getRates($lotto_id,$disk, $bettype, $subid);

            if ($tempRateBaseArr == false)
            {
                $betOKFlag = false;
                $showBetTable[] = array ("subid" => $subid, "bettype" => $betname_sb[$betnameIdx], "nums" => $RateConfig_sb->getBetContent($bettype, $nums), "rate" => "--", "betmoney" => "<font class=\"red\">无赔率资料无法下注</font>", "betflag" => false);
                $errMsg = "({$tbl})会员下注:无该玩法之赔率值:id-{$bettype}, subid-{$subid}";
                write_exceptional_log($curruser['id'], $curruser['acl'], $lotto_id, $errMsg);
                continue;
            }
            if ($tempRateBaseArr2 = $SRate_sb->getRatesS($lotto_id, $bettype, $user_id, $subid))
            {
                $tempRateArr = array ();
                foreach ($tempRateBaseArr as $key2 => $val2)
                {
                    $tempRateArr[$key2] = $tempRateBaseArr[$key2] - $tempRateBaseArr2[$key2];
                }
                $rateArr[$betnameIdx] = $tempRateArr;
            }
            else
            {
                $rateArr[$betnameIdx] = $tempRateBaseArr;
            }
        }
        $rate = $RateConfig_sb->getRateFromRateArr($bettype, $nums, $rateArr[$betnameIdx]);
        if ($rate <= 1)
        {
            $betOKFlag = false;
            $showBetTable[] = array ("subid" => $subid, "bettype" => $betname_sb[$betnameIdx], "nums" => $RateConfig_sb->getBetContent($bettype, $nums), "rate" => "--", "betmoney" => "<font class=\"red\">赔率值错误无法下注</font>", "betflag" => false);
            $errMsg = "({$tbl})会员下注:赔率值错误:id-{$bettype},num-{$nums}, subid-{$subid}";
            write_exceptional_log($curruser['id'], $curruser['acl'], $lotto_id, $errMsg);
            continue;
        }
        if ($betOKFlag)
        {
            $showBetTable[] = array ("subid" => $subid, "bettype" => $betname_sb[$betnameIdx] . "<input type=\"hidden\" name=\"b_{$subid}_{$bettype}_{$nums}\" value=\"{$val}\" />", "nums" => $RateConfig_sb->getBetContent($bettype, $nums), "rate" => $rate . "<input type=\"hidden\" name=\"rate{$bettype}v{$nums}v{$subid}\" value=\"{$rate}\" />", "betmoney" => $val, "betflag" => true);
        }
    }
   
    if (intval(getvar("qFast")))
    {
        $qFast = "1";
    }
    else
    {
        $qFast = "";
    }
    if ($qFast)
    {
        $qFastStr = "&qFast={$qFast}";
    }
    else
    {
        $qFastStr = "";
    }
    $ui->header();
    $ui->showNews3D($curruser['acl']);
    echo "<div></div>";
    echo "<form action=\"op.php?op=member_sb&fp=bet_do&palygroup=" . $bettypegroup . "&gametype=" . $gametype . "&disk=" . $disk . "\" method=\"post\" onsubmit=\"this.submit.disabled=true;this.reset.disabled=true\">";
    echo "<input type=\"hidden\" value=\"" . $bettypegroup . "\" name=\"bettypegroup\" />";
    echo "<input type=\"hidden\" value=\"" . $gametype . "\" name=\"gametype\" />";
    echo "<input type=\"hidden\" value=\"" . $subid . "\" name=\"subid\" />";
    echo "<input type=\"hidden\" value=\"" . $disk . "\" name=\"disk\" />";
    echo "<input type=\"hidden\" value=\"" . $qFast . "\" name=\"qFast\" />";
    if ($rcbettype)
    {
        echo "<input type=\"hidden\" value=\"" . $rcbettype . "\" name=\"rcbettype\" />";
    }
    echo "<table class=\"tblMy3D\">";
    echo "<thead><tr class=\"bgImg_" . $gametype . "\"><th colspan=5>" . $tblName . " 第" . $round . "期 您下注的是：</th></tr>";
    echo "<tr class=\"bgClc_" . $gametype . "\">";
    echo "<th>下注类型</th><th>下注内容</th><th>盘类</th><th>赔率</th><th>下注金额</th></tr></thead>";
    echo "<tbody>";
    $totalmon = 0;
    foreach ($showBetTable as $val)
    {
        echo "<tr class=\"td2\">";
		echo "<td>" . $val['bettype'] . "</td>";
        echo "<td>" . $val['nums'] . "</td>";
        echo "<td>" . $diskStr2 . "</td>";
        echo "<td>" . $val['rate'] . "</td>";
        echo "<td align=\"right\">" . $val['betmoney'] . "</td>";
        if ($val['betflag'])
        {
            $totalmon += $val['betmoney'];
        }
        echo "</tr>";
    }
    $timebtnType = getvar("timebtnType") == "checkbox" ? "checkbox" : "text";
    unset($_POST['timebtnType']);
    $backurl = "op.php?op=member_sb&fp=bet&palygroup={$bettypegroup}&timebtnType={$timebtnType}&gametype={$gametype}&disk={$disk}&xyid={$xyidGet}&subid={$subid}&rcbettype={$rcbettype}{$qFastStr}";
    if (0 < $totalmon)
    {
        echo "<tr class=\"bgClc_" . $gametype . "\" align=\"right\"><td colspan=\"4\">合计</td><td>" . $totalmon . "</td></tr>";
        echo "<tr class=\"bgClc_24\"><td colspan=\"5\" align=\"center\" style=\"color:red;\"><input type=\"checkbox\" name=\"recentNew\" value=\"1\" checked />强制(赔率异动时，依新赔率下注)</td></tr>";
        $btnStr = "<input type=\"submit\" name=\"submit\" value=\"确定下注\" />&nbsp;&nbsp;<input name=\"reset\" type=\"reset\" value=\"取消下注\" onclick=\"javascript:window.top.mainFrame.location.href='" . $backurl . "';\" />";
        $focusStr = "document.forms[0].submit.focus();";
    }
    else
    {
        echo "<tr class=\"red\"><td colspan=\"6\" align=\"center\">无任何可下注资料</td></tr>";
        $btnStr = "<input name=\"reset\" type=\"reset\" value=\"回上一页\" onclick=\"javascript:window.top.mainFrame.location.href='" . $backurl . "';\" />";
        $focusStr = "";
    }
    echo "</tbody>";
    echo "</table>";
    echo $btnStr;
    echo "<input type=\"hidden\" value=\"" . $timebtnType . "\" name=\"timebtnType\" id=\"timebtnType\" />";
    echo "</form>";
    echo "<script>";
    echo $focusStr;
    echo "</script>";
    $ui->footer();
}
?>